﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MimiDouban.Abstract;
using System.Timers;
using System.Windows.Threading;
using System.Windows.Media.Animation;

namespace MimiDouban.UI
{
    /// <summary>
    /// 用于显示右下角文字的类
    /// </summary>
    public partial class TipsOutputUI : Window,IOutputUI
    {
        //主窗口引用，只有当主窗口为最小化时，才显示内容
        private Window mainWindow;
        private Timer timer;
        private delegate void hideMeDelType();
        private hideMeDelType hideMeDel;

        private Storyboard story;

        public TipsOutputUI(Window mainWindow)
        {
            InitializeComponent();
            this.mainWindow = mainWindow;
        }

        #region IOutputUI Members

        public void start()
        {
            //throw new NotImplementedException();
        }

        public void ShowSongInfo(MimiDouban.Abstract.Beans.DoubanSong song)
        {
            //throw new NotImplementedException();
        }

        public void ShowChannel(MimiDouban.Abstract.Beans.DoubanChannel channel)
        {
            //throw new NotImplementedException();
        }

        public void ShowNextSong(MimiDouban.Abstract.Beans.DoubanSong song)
        {
            if (mainWindow.WindowState == WindowState.Minimized)
            {
                txtMessage.Text = "下一首：" + song.Title;
                showMe();
            }
        }                 

        public void showTime(int min, int sec)
        {
        }
        public void showBuffer(string str)
        {
        }

        public void showVolume(double volume)
        {
        }

        public void setLikeStatus(ControlStatus status)
        {
            if (mainWindow.WindowState == WindowState.Minimized)
            {
                txtMessage.Text = (status == ControlStatus.Pressed ? "我喜欢" : "取消我喜欢");
                showMe();
            }
        }

        public ControlStatus getLikeStatus()
        {
            //throw new NotImplementedException();
            return ControlStatus.Enabled;
        }

        public void setDislikeStatus(ControlStatus status)
        {
            //throw new NotImplementedException();
        }

        public void setPauseStatus(bool status)
        {
            //throw new NotImplementedException();
        }

        public void showLogin()
        {
            //throw new NotImplementedException();
        }

        public MimiDouban.Abstract.Beans.DoubanChannel[] Channels
        {
            get
            {
                //throw new NotImplementedException();
                return null;
            }
            set
            {
                //throw new NotImplementedException();
            }
        }

        public void end()
        {
            this.Close();
        }


        public void showCurrentUser(string username)
        {
            //throw new NotImplementedException();
        }

        public void showLoginBtn()
        {
            //throw new NotImplementedException();
        }

        #endregion

        private void showMe()
        {
            double screenHeight = SystemParameters.PrimaryScreenHeight;
            double screenWidth = SystemParameters.PrimaryScreenWidth;
            this.Top = screenHeight - this.Height - 50;
            this.Left = screenWidth - this.Width - 50;

            //先把上一次动画停下来
            if (story != null && story.GetCurrentState() == ClockState.Active)
            {
                story.Stop();
            }

            //开始动画
            this.Show();
            story = (Resources["ShowText"] as Storyboard);
            story.Begin();
        }

        private void ShowText_Completed(object sender, EventArgs e)
        {
            this.txtMessage.Text = "";
            this.Hide();
        }     
    }
}
